package com.lu.mediarecorder;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.VideoView;

import com.lu.mediarecorder.util.FileUtil;


/**
 * 使用系统自带的录像工具录制视频
 *
 */
public class VideoViewActivity extends AppCompatActivity {

    private VideoView vvVideoView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_system_record);
        initView();
    }

    private void initView() {
        vvVideoView = findViewById(R.id.video);
    }

    public void systemCapture(View v) {
        Uri uri = Uri.fromFile(FileUtil.newMp4File());
        Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
        intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, 10);
        startActivityForResult(intent, 10);
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            switch (requestCode) {
                case 10:
                    vvVideoView.setVideoURI(data.getData());
                    vvVideoView.start();
                    break;
            }
        }
    }

}
